package com.socket;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * Created by peak on 2016/1/14.
 */
public class socketClient {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("localhost",8000);
        socket.setSoTimeout(10000);
        PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()),true);
        printWriter.println("GET / HTTP/1.1");
        printWriter.println("HOST:localhost");
        printWriter.println("connection:close");
        printWriter.println();

        InputStream in = socket.getInputStream();


        int byteCount=0;
        int i=-1;
        while((i=in.read())!=-1){
            System.out.print((char)i);
        }
        System.out.println("byteCount="+byteCount);
        in.close();
        socket.close();
    }
}
